//
//  ViewController.m
//  富文本测试
//
//  Created by 生龙 on 16/4/15.
//  Copyright © 2016年 龙. All rights reserved.
//

#import "ViewController.h"
#import "DataModel.h"
#import "TableViewCell.h"
#import "YYText.h"

#define KRandomColor [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArr;



@end

@implementation ViewController

- (NSMutableArray *)dataArr{
    
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    
    for (int i = 0; i < 30 ; i ++) {
        
        DataModel *model = [[DataModel alloc] init];
        model.attrStr = [NSMutableAttributedString new] ;
        model.name = [NSString stringWithFormat:@"陈-->%d",i + 1];
        model.iconStr = @"http://tx.haiqq.com/qqtouxiang/uploads/2014-09-19/112110225.jpg";
        
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"我是一个好学生"];
        NSAttributedString *attrStr = [NSMutableAttributedString yy_attachmentStringWithEmojiImage:[UIImage imageNamed:@"timg"] fontSize:20];
        UISwitch *switchV = [[UISwitch alloc] init];
         NSAttributedString *attachText = [NSMutableAttributedString yy_attachmentStringWithContent:switchV contentMode:UIViewContentModeCenter attachmentSize:switchV.frame.size alignToFont:[UIFont systemFontOfSize:16] alignment:YYTextVerticalAlignmentCenter];
//        [model.attrStr appendAttributedString:str];

        [model.attrStr appendAttributedString:attachText];
        [model.attrStr appendAttributedString:attrStr];
        
        [self.dataArr addObject:model];
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testcell" forIndexPath:indexPath];
//    cell.backgroundColor = KRandomColor;
    
    DataModel *model = self.dataArr[indexPath.row];
    cell.dataModel = model;
    return cell;
}

@end
